/*
This file is part of IRCaBot.
IRCaBot is IRC logger with features.
Source code: https://notabug.org/acetone/ircabot.
Copyright (C) acetone, 2023.

This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.

This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
GNU General Public License for more details.

You should have received a copy of the GNU General Public License
along with this program.  If not, see <https://www.gnu.org/licenses/>.
*/

#pragma once

#include <QString>
#include <QStringList>
#include <QSharedPointer>

class IRCNetworkClient;
class HttpRequestToVoiceGate;
class QJsonObject;
class IRCNetworkClientStarter;
class AdminIRCPanel;

class Config
{
    friend AdminIRCPanel;
    friend HttpRequestToVoiceGate;
    friend IRCNetworkClientStarter;

public:
    Config() = delete;

    // default values defined in initFromJson()
    struct Network
    {
        QString ircabotAdmin;
        QString networkName;
        QString host;
        quint16 port;
        bool ssl;
        QString nickname;
        QString password;
        QString identifyFormat;
        QString ident;
        QString realName;
        QStringList channels;
        bool autoReconnect;
        bool voiceGate;
        bool hideMessageByLeadingDot;
        QStringList bridgeNicknames;

        IRCNetworkClient* instance = nullptr;
    };

    struct VoiceGate
    {
        int captchaDifficulty;
        int captchaCacheSize;
        bool captchaOnlyNumbers;
        bool captchaCaseSensitive;
    };

    static void setConfigurationFilePath(const QString& path) { m_configurationFilePath = path; }
    static bool initFromFile(QString* errorString = nullptr);
    static bool initFromJson(const QJsonObject& config, QString* errorString = nullptr);
    static bool updateConfigWithCurrentData(QString* errorString = nullptr);

    static const QString& configurationFilePath()             { return m_configurationFilePath; }
    static const QString& logFilePath()                       { return m_logFilePath; }
    static const QString& logFileDateFormat()                 { return m_logFileDateFormat; }

    static const QString& webUiAddress()                      { return m_webUiAddress; }
    static quint16 webUiPort()                                { return m_webUiPort; }
    static int webUiThreads()                                 { return m_webUiThreads; }
    static QStringList webUiBaseUrls()                        { return m_webUiBaseUrls; }

    static const QString& workingDirectory()                  { return m_workingDirectory; }

    static bool utcTime()                                     { return m_utcTime; }
    static int ircAdminAuthorizationTimeout()                 { return m_ircAdminAuthorizationTimeout; }

    static const QList<QSharedPointer<Network>>& networks()   { return m_networks; }
    static const VoiceGate voiceGate()                        { return m_voiceGate; }

private:
    static QList<QSharedPointer<Network>>& networksAccess()   { return m_networks; }
    static VoiceGate& voiceGateAccess()                       { return m_voiceGate; }
    static QString m_configurationFilePath;
    static QString m_logFilePath;
    static QString m_logFileDateFormat;
    static QString m_workingDirectory;

    static QStringList m_webUiBaseUrls;
    static QString m_webUiAddress;
    static quint16 m_webUiPort;
    static uint m_webUiThreads;

    static VoiceGate m_voiceGate;

    static bool m_utcTime;
    static uint m_ircAdminAuthorizationTimeout;

    static QList<QSharedPointer<Network>> m_networks;
};

